package com.drawingtimer.admin.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.drawingtimer.admin.converter.TProcessFlowCardConverter;
import com.drawingtimer.admin.model.entity.TProcessFlowCard;
import com.drawingtimer.admin.model.qo.TProcessFlowCardQO;
import com.drawingtimer.admin.model.vo.TProcessFlowCardPageVO;
import com.hccake.ballcat.common.model.domain.PageParam;
import com.hccake.ballcat.common.model.domain.PageResult;
import com.hccake.extend.mybatis.plus.conditions.query.LambdaQueryWrapperX;
import com.hccake.extend.mybatis.plus.mapper.ExtendMapper;
import com.hccake.extend.mybatis.plus.toolkit.WrappersX;
import org.apache.commons.lang3.StringUtils;

/**
 * 工序流转卡信息
 *
 * @author jjh 2025-04-24 16:34:16
 */
public interface TProcessFlowCardMapper extends ExtendMapper<TProcessFlowCard> {

	/**
	 * 分页查询
	 * @param pageParam 分页参数
	 * @param qo 查询参数
	 * @return PageResult<TProcessFlowCardPageVO> VO分页数据
	 */
	default PageResult<TProcessFlowCardPageVO> queryPage(PageParam pageParam, TProcessFlowCardQO qo) {
		IPage<TProcessFlowCard> page = this.prodPage(pageParam);
		LambdaQueryWrapperX<TProcessFlowCard> wrapper = WrappersX.lambdaQueryX(TProcessFlowCard.class);
		if (!StringUtils.isEmpty(qo.getCardNumber())) {
			wrapper.like(TProcessFlowCard::getCardNumber, qo.getCardNumber().trim());
		}
		if (!StringUtils.isEmpty(qo.getMoNumber())) {
			wrapper.like(TProcessFlowCard::getMoNumber, qo.getMoNumber().trim());
		}
		if (!StringUtils.isEmpty(qo.getMaterialCode())) {
			wrapper.like(TProcessFlowCard::getMaterialCode, qo.getMaterialCode().trim());
		}
		this.selectPage(page, wrapper);
		IPage<TProcessFlowCardPageVO> voPage = page.convert(TProcessFlowCardConverter.INSTANCE::poToPageVo);
		return new PageResult<>(voPage.getRecords(), voPage.getTotal());
	}

}